--[[/**
-- * 
 * 每次触发时,以自身最大血量的 万分比  扣除周围敌人的血量
 * [0] 距离 万分比
 * [1] n 万分比
-- *
-- */]]

---@class BuffEffect223100 : BaseBuffEffect
BuffEffect223100 = ClientFight.CreateClass("BuffEffect223100", ClientFight.BaseBuffEffect)
local t = BuffEffect223100

---@param fight Fight
---@param buff FighterBuff
function t:action(fight, buff, ...)
    local maxHp = FighterAttributeManager.getFightAttr(buff.target, FighterAttributeEnum.HP);
    local reduce = Utils.calcRatio(maxHp, buff.buffBean.f_BuffEffectValue[2]);
    if (reduce < 1) then
        return IBuffEffect.FAIL;
    end
    local team = fight.teams[1 - buff.target.teamIndex];
    local dis = Utils.toRatio(buff.buffBean.f_BuffEffectValue[1]);
    local fighters = clone(team.fighters);
    for fighter in pairs(fighters) do
        if (fighter:isDie()) then
            goto continue;
        end
        if (fighter:isSummons() and not fighter.isRealSummons()) then
            goto continue;
        end
        local distance = DistanceUtil.countDistance(fighter.position, buff.target.position);
        if (distance > dis) then
            goto continue;
        end
        SkillRoleMgr.savePathFile("[" .. fight.frame .. "][EFFECT]Fighter " .. buff.target.fighterId .. " Buff:"
                .. buff.modelId .. " 扣除周围敌人的血量(" .. fighter.fighterId .. ") " .. reduce .. " 点");
        local realDamage = DamageManager.setFighterHp(fight, fighter, buff.target, nil, DamageResultTypeEnum.NORMAL, -reduce, fighter.hp - reduce, true, true, true);
        DamageManager.setFighterHp(fight, buff.target, buff.target, nil, DamageResultTypeEnum.HEAL, reduce, buff.target.hp + reduce, false, false, true);
        :: continue ::
    end
    return ClientFight.BaseBuffEffect.action(self, fight, buff, ...);

end

t.New()